package top.hkyzf.study.leetcode.array;

import org.junit.Test;

/**
 * @author zhufeng
 * @version 1.0
 * @date 2022-2-26 22:06
 */
public class 增量元素之间的最大差值_2016 {
    public int maximumDifference(int[] nums) {
        int minNum = nums[0];
        int maxDiff = -1;
        for (int i = 1; i < nums.length; i++) {
            if (minNum < nums[i]) {
                maxDiff = Math.max(maxDiff, nums[i] - minNum);
            } else {
                minNum = nums[i];
            }
        }
        return maxDiff;
    }

    @Test
    public void testMaximumDifference () {
        int[] nums = {7,1,5,4};
        System.out.println(maximumDifference(nums));
    }
}
